/**
 * @param {number} time
 * @returns {string}
 */
export function formatTime(time) {
	const d = new Date(time).getTime()
	const now = Date.now()
	const diff = (now - d) / 1000
	if (diff < 30) {
		return '刚刚'
	} else if (diff < 3600) {
		// less 1 hour
		return Math.ceil(diff / 60) + '分钟前'
	} else if (diff < 3600 * 24) {
		return Math.ceil(diff / 3600) + '小时前'
	} else if (diff < 3600 * 24 * 2) {
		return '1天前'
	} else if (diff >= 3600 * 24 * 2) {
		return Math.ceil(diff / 3600 / 24) + '天前'
	}
}
export function frameTime(time) {
	const now = new Date(time)
	const hours = now.getHours();
	let frameHours = ''
	if (hours < 12) {
		frameHours = '上午'
	} else {
		frameHours = '下午'
	}
	return frameHours
}
export function timestampToDate(time) {
	const date = new Date(time)

	const year = date.getFullYear();
	const month = String(date.getMonth() + 1).padStart(2, '0');
	const day = String(date.getDate()).padStart(2, '0');
	const hours = String(date.getHours()).padStart(2, '0');
	const minutes = String(date.getMinutes()).padStart(2, '0');
	const seconds = String(date.getSeconds()).padStart(2, '0');

	const timestampToDate = new Intl.DateTimeFormat('zh-CN', options).format(date)

	const options = {
		year: 'numeric',
		month: 'long',
		day: 'numeric'
	};
	let frameHours = ''
	if (hours < 12) {
		frameHours = '上午'
	} else {
		frameHours = '下午'
	}

	// 使用Intl.DateTimeFormat进行格式化
	// return new Intl.DateTimeFormat('zh-CN', options).format(date); 
	return `${month}月${day}日${frameHours} ${hours}：${minutes}`
}


export function currenTime(time) {
	const currentTime = new Date();
	const year = currentTime.getFullYear();
	const month = currentTime.getMonth() + 1; // 月份从0开始，因此需要加1
	const day = currentTime.getDate();
	const hours = currentTime.getHours();
	const minutes = currentTime.getMinutes();
	const seconds = currentTime.getSeconds();
	// console.log(year, month, day, hours, minutes, seconds);
	return year + '-' + month + '-' + day
}